var co = require('co');
var moment = require("moment");
var fs = require('fs');
var formidable = require('formidable');
var seqModule = require('../../models/index');
var db = new seqModule();
var util = require('../../common/util');
var speakHostController = {
    getSpeakHost: function (req, res) {
        co(function () {
            //var page = parseInt(req.query.page);
            var params = {};
            var paramT = {};
            if (req.query.pTitle != undefined) {
                params["$or"] = { "name": { "$like": "%" + req.query.pTitle + "%" }, "tel": { "$like": "%" + req.query.pTitle + "%" } ,"hospitalName":{ "$like": "%" + req.query.pTitle + "%" }};
            }
            paramT["where"] = params;
            paramT["order"] = [["name", 'ASC']];
            db.speakHostModule.findAll(paramT).then(function (result) {
                res.status(200).json(result);
            });
        }).catch(function (e) {
            res.status(500).json({"message":"服务异常！"});
            console.log(e);
        })
    },
    getSpeakHostByTel: function (req, res) {
        co(function () {
            //var page = parseInt(req.query.page);
            var params = {};
            var paramT = {};
            if (req.params.tel != undefined) {
               params.tel = req.params.tel;
            }
            paramT["where"] = params;
            db.speakHostModule.findOne(paramT).then(function (result) {
                res.status(200).json(result);
            });
        }).catch(function (e) {
            res.status(500).json({"message":"服务异常！"});
            console.log(e);
        })
    }
}
module.exports = speakHostController;